<template>
  <div class="pay">
      <div class="hb" @click="closePay"></div>
      <div class="info">
        <p class="title">投注项目</p>
        <div class="item">
          <p class="txtle">{{matchName}}</p>
          <p class="txtle">{{team|title}} {{team|txtle}}</p>
        </div>
      
        <div class="inputBox">
            <p class="enter"><span>积分</span><input type="number" v-model="price" placeholder="请输入投注积分" name=""></p>
            <p class="enterClick">
              <span @click="enterClick(1000)">1000</span>
              <span @click="enterClick(500)">500</span>
              <span @click="enterClick(200)">200</span>
              <span @click="enterClick(100)">100</span>
            </p>
            <div class="click">
              <div class="message">
                <p>赢取积分：{{count}}</p>
                <p>可用积分：{{inte}}</p>
              </div>
              <button @click="getPay">确定</button>
            </div>
            
        </div>
      </div>
  </div>
</template>

<script>
import '@/assets/style/common.less'
import {Get,Post,Put,Del} from '@/api/index.js'
export default {
  name: 'pay',
  data () {
    return {
      price:50,
      team:'',
      inte:'',//个人积分
      matchId:'',//比赛id
      matchName:'',//比赛名称
      odds:''//赔率
    }
  },
  computed:{
    count(){
      return this.odds*this.price
    }
  },
  filters:{
      filte(e){
          let time=e.substring(10,16)
          return time
      },
      title(e){
        let title
        let date=e
        if(date.total_score_max!=undefined){
          title="总分大于"
        }else if(date.total_score_min!=undefined){
          title="总分小于"
        }else if(date.home_let_point!=undefined){
          title="主队全场"
        }else if(date.home_half_let_point!=undefined){
          title="主队半场"
        }else if(date.away_let_point!=undefined){
          title="客队全场"
        }else if(date.away_half_let_point!=undefined){
          title="客队半场"
        }
        return title
      },
      txtle(e){
        let title
        let date=e
        if(date.total_score_max!=undefined){
          title=date.total_score_max
        }else if(date.total_score_min!=undefined){
          title=date.total_score_min
        }else if(date.home_let_point!=undefined){
          title=date.home_let_point
        }else if(date.home_half_let_point!=undefined){
          title=date.home_half_let_point
        }else if(date.away_let_point!=undefined){
          title=date.away_let_point
        }else if(date.away_half_let_point!=undefined){
          title=date.away_half_let_point
        }
        return title
      }
  },
  mounted(){
    this.getDate()
  },
  methods:{
    //关闭投注窗
    closePay(){
      this.$store.dispatch('payStart', false)
    },
    //获取投注信息
    async getDate(){
      let reg=await Get('/sport/match/set/'+this.$store.state.payId,this.$store.state.token)
      this.team=JSON.parse(reg.data.content)
      this.matchId=reg.data.match_id
      this.odds=reg.data.odds

      //获取比赛信息
      let kk=await Get('/sport/match/'+this.matchId,this.$store.state.token)
      this.matchName=kk.data.match_name

      //获取个人积分
      let me=await Get('/users/me',this.$store.state.token)
      this.inte=me.data.integral_count


    },
    //点击投注
    getPay(){
      if(this.vLogin()){
        if(this.price>50){
          let date={
            "buy_amount":this.price,
            "match_set_id":this.$store.state.payId
          };
          Post('/sport/order',this.$store.state.token,date).then(function(){
            alert('投注成功！')
          }).catch(function(err){
            alert(err.response.data.message)
          })
          this.$store.dispatch('payStart', false)
          
        }else{
          this.price=50
          alert('最低投注50积分！')
        }
        
      }else{
        this.$store.dispatch('payStart', false)
        this.$router.push('/login')
      }
    },

    enterClick(val){
        this.price=val
    }
  }
}
</script>

